package leetcode.code1669;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;
import leetcode.helper.tree.ListNode;

public class Solution implements IDebug {

	public ListNode mergeInBetween(ListNode list1, int a, int b, ListNode list2) {
		ListNode ans = new ListNode();
		ans.next = list1;
		ListNode l = list1;
		int move = a;
		while (move > 1) {
			l = l.next;
			move--;
		}
		b = b - a;
		ListNode r = l;
		while (b > -1) {
			r = r.next;
			b--;
		}
		l.next = list2;
		while (list2.next != null) {
			list2 = list2.next;
		}
		list2.next = r.next;
		return ans.next;
	}

	@Override
	public void debug1() {
		ListNode e = ListNode.set(HelpDebug.str2array3("[0,1,2,1000000,1000001,1000002,5]"));
		HelpDebug.compare(e, this.mergeInBetween(ListNode.set(HelpDebug.str2array3("[0,1,2,3,4,5]")), 3, 4, ListNode.set(HelpDebug.str2array3("[1000000,1000001,1000002]"))));

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
